package com.zzj.controller;

import com.github.pagehelper.PageInfo;
import com.zzj.bean.EmployeeBean;
import com.zzj.service.EmpService;
import com.zzj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private EmpService empService;


    /**
     * 添加一名员工
     * @param employeeBean
     * @return result
     */
    @PostMapping("addEmp")
   public Result addEmp(@RequestBody EmployeeBean employeeBean){
        System.out.println(employeeBean);
       return  empService.addEmp(employeeBean);
   }

    /**
     * 通过员工ID删除一名员工
     * @param eid
     * @return
     */
    @PostMapping("delEmp")
    public Result delEmp(int eid){
       return empService.delEmp(eid);
    }

    /**
     * 通过员工ID修改一名员工的信息
     * @param employeeBean
     * @return
     */
    @PostMapping("updEmp")
    public Result updateEmp(@RequestBody EmployeeBean employeeBean){
        System.out.println("employeeBean = " + employeeBean);
        return empService.updateEmp(employeeBean);
    }

    /**
     * 查看所有员工的信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("findAllEmp")
    public Result<PageInfo<EmployeeBean>> findAllEmp(@RequestParam(defaultValue = "1") Integer pageNum,
                                                      @RequestParam(defaultValue = "5") Integer pageSize){
        return empService.findAllEmpl(pageNum,pageSize);
    }

    /**
     * @param eid
     * @return
     */
    @GetMapping("findEmpById")
    public Result<EmployeeBean> findEmpByEid(int eid){
        return empService.findEmpByEid(eid);
    }

}
